﻿using System;
using System.Reflection;

namespace Rodunu.Utilities.Reflection
{
    public class GenericClassHelper<T>
    {
        public object GetProperty(T initialObject, string propKeyName)
        {
            PropertyInfo keyProp;
            object keyPropertyValue;
            try
            {
                keyProp = typeof(T).GetProperty(propKeyName);
                keyPropertyValue = keyProp.GetValue(initialObject, null);
            }
            catch
            {
                throw new Exception("Property doesn't exist.");
            }

            return keyPropertyValue;
        }
    }
}
